<html>
<head><meta charset="utf-8"><title>rust-analyzer#963 · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html">rust-analyzer#963</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="161243366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161243366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161243366">(Mar 20 2019 at 12:50)</a>:</h4>
<p>I was wondering what would be the best way to go about refactoring the building of <code>CallInfo::label</code>, currently we build the label using <code>completion::function_label</code> which preserves the original formatting and information (parameters + including generics and where clauses) and then we extract the parameters separately, which may or may not match exactly since they are turned into a <code>String</code> manually.</p>
<p>Simplest solution would probably be just turning the <code>ast::FnDef</code> params directly into text, and then in <code>conv</code> implementing <code>Conv</code> for <code>ra_ide_api::CallInfo</code> and turning it into <code>lsp_types::SignatureInformation</code> where we ensure the LSP requirements that the parameters are a substring of the label, we could also turn them into offsets here if wanted.</p>
<p>Another possible solution is to change the <code>CallInfo</code> so that it doesn't contain a single <code>label</code> but all the parts that make it and then build the label separately. e.g.</p>
<div class="codehilite"><pre><span></span><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">CallInfo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Documentation for the function</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">doc</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="n">Documentation</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Name of the function</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">name</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Parameters of the function</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">parameters</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Generic parameters</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">generic_parameters</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Predicates</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">where_predicates</span>: <span class="nb">Vec</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Return type</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">ret</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>

<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="n">active_parameter</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="kt">usize</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>This would make it easy to ensure that the parameters are actual substrings of the label, but it would mean we'd need to implement some sort of pretty printing for creating the output label.</p>



<a name="161252108"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161252108" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161252108">(Mar 20 2019 at 14:28)</a>:</h4>
<p>The letter approach seems reasonable. In general, we shouldn't rely on FnDef when making a CallInfo</p>



<a name="161252121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161252121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161252121">(Mar 20 2019 at 14:28)</a>:</h4>
<p>Consider the case where you are calling a lambda function</p>



<a name="161252148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161252148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161252148">(Mar 20 2019 at 14:28)</a>:</h4>
<p>It still has parameter types and return type, but they are not present in the source text. We should reconstruct them from type-inference information</p>



<a name="161252212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161252212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161252212">(Mar 20 2019 at 14:29)</a>:</h4>
<p>So, <code>CallInfo</code> indeed should contain abstract pieces of information, and rendering them to whatever representation the client wants should be a consern of a client</p>



<a name="161256052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161256052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161256052">(Mar 20 2019 at 15:08)</a>:</h4>
<p>I prefer the latter approach as well. Whichever way we go I think we should use the same scheme for completion and hover.</p>



<a name="161256859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161256859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161256859">(Mar 20 2019 at 15:16)</a>:</h4>
<p>Maybe instead of having it being specific to a <code>CallInfo</code> make something like <code>FunctionSignature</code> that contains the information that can be contained in the <code>CallInfo</code> but also be used directly by hover and completion, then make similar structure for other types as well.</p>



<a name="161257005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161257005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161257005">(Mar 20 2019 at 15:18)</a>:</h4>
<p>Then we can implement some sort of pretty printing that can be used for UI purposes</p>



<a name="161257188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161257188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161257188">(Mar 20 2019 at 15:20)</a>:</h4>
<p>So some sort of common intermediate structures for types and signatures</p>
<div class="codehilite"><pre><span></span><span class="k">struct</span> <span class="nc">TypeWithName</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">name</span>: <span class="nb">String</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">typ</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// const, static etc.</span>
<span class="w">    </span><span class="n">modifier</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>



<a name="161257314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161257314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vipentti <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161257314">(Mar 20 2019 at 15:21)</a>:</h4>
<p>Then displaying would be the responsibility of the client, and we could have functions for turning <code>AstNodes</code> into corresponding intermediate structures</p>



<a name="161258348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161258348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161258348">(Mar 20 2019 at 15:34)</a>:</h4>
<p>Yeah I like the <code>FunctionSignature</code> idea. That would make it easier to say.... switch the presentation of generic arguments if the user wanted</p>



<a name="161258413"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer%23963/near/161258413" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/rust-analyzer.23963.html#161258413">(Mar 20 2019 at 15:34)</a>:</h4>
<p>between <code>arg1 : T</code> vs <code>where</code> syntax or whatever</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>